<?php

namespace Havoo\Core;

class View
{

    protected $_variables = array();
    protected $_controller;
    protected $_action;
    protected $_layout = 'default';

    public function __construct($controller, $action)
    {
        $this->_controller = strtolower($controller);
        $this->_action = strtolower($action);
    }

    public function assign($name, $value)
    {
        $this->_variables[$name] = $value;
    }

    public function setLayout($layout)
    {
        $this->_layout = $layout;
    }

    public function render($file = '')
    {
        extract($this->_variables);
        $controller = $this->_controller;
        $action = $file ? : $this->_action;
        $layout = APP_PATH . '/Views/layouts/' . $this->_layout . '.php';
        if (file_exists($layout)) {
            include $layout;
        }
    }

}
